package com.zlcx.tz.live.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.UpdateTimestamp;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.io.Serializable;
import java.util.Date;

/**
 * @author anjl
 * 计时学习自习室座位信息
 */

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "tz_time_learn_room_seats")
@JsonSerialize
@DynamicUpdate
@DynamicInsert
public class TimeLearnRoomSeatsDO implements Serializable {

    private static final long serialVersionUID = 2784368511288937374L;

    @Id
    @GeneratedValue
    private Long id;

    /**
     * 房间id
     */
    private Long roomId;

    /**
     * 用户id
     */
    private Long userId;

    /**
     * 入座时间
     */
    private Date seatingTime;

    /**
     * 结束时间
     */
    private Date sitUpTime;

    /**
     * 学习内容id
     */
    private Long contentId;

    /**
     * 学习内容
     */
    private String studyContent;

    /**
     * 计时分钟数
     */
    private Integer minutes;

    /**
     * 座位编号
     */
    private Integer num;

    private Integer useOtherApps;

    @CreationTimestamp
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @UpdateTimestamp
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    public void putUser(Long userId, Long contentId, String content, Integer minutes, Integer useOtherApps) {
        this.setUserId(userId);
        this.setSeatingTime(new Date());
        this.setContentId(contentId);
        this.setStudyContent(content);
        this.setUseOtherApps(useOtherApps);
        this.setMinutes(minutes);
    }

    /**
     * 清空座位上的用户信息
     */
    public void clear() {
        this.setSeatingTime(null);
        this.setUserId(null);
        this.setStudyContent(null);
        this.setContentId(null);
        this.setUseOtherApps(null);
        this.setMinutes(null);
    }

}